package manager.modulo.financeiro;

import java.sql.SQLException;
import java.util.LinkedList;
import javax.swing.JOptionPane;
import javax.swing.UIManager;
import javax.swing.table.TableRowSorter;
import manager.auxiliares.Configurations;
import manager.auxiliares.Format;
import manager.auxiliares.Icons;
import manager.auxiliares.MensagemExcessao;
import manager.auxiliares.WindowsFunctions;
import manager.helpers.table.TableModel;
import manager.helpers.table.TableRender;
import manager.helpers.table.TableRowComparator;
import manager.helpers.validation.TextFieldValidator;
import manager.helpers.validation.ValidationFunctions;
import manager.principal.fonte.JanelaLogin;
import manager.interfaces.InterfaceTable;
import manager.modulo.financeiro.dao.FinancialCategoryDao;
import manager.modulo.financeiro.dao.SecondaryCategoryDao;
import manager.modulo.financeiro.dao.EntryTypeDao;

/**
 *
 * @author Thiago
 */
public class JanelaCategoriaFinanceira extends javax.swing.JFrame {

    int idFinancialCategory = 0;
    TableModel tableModel;
    TableRender tableRender;
    TableRowSorter tableRowSorter;
    //Secondary Category options
    int idSecondaryCategory = 0;
    int idPosition = 0;
    LinkedList<SecondaryCategoryObject> secondaryCategoryList;

    public class SecondaryCategoryObject {

        int idSecondaryCategory;
        String name;
        int situation;
        int idFinancialCategory;

        public SecondaryCategoryObject() {
            idSecondaryCategory = 0;
            name = "";
            situation = 0;
            idFinancialCategory = 0;
        }

        public int getIdFinancialCategory() {
            return idFinancialCategory;
        }

        public void setIdFinancialCategory(int idFinancialCategory) {
            this.idFinancialCategory = idFinancialCategory;
        }

        public int getIdSecondaryCategory() {
            return idSecondaryCategory;
        }

        public void setIdSecondaryCategory(int idSecondaryCategory) {
            this.idSecondaryCategory = idSecondaryCategory;
        }

        public String getName() {
            return name;
        }

        public void setName(String name) {
            this.name = name;
        }

        public int getSituation() {
            return situation;
        }

        public void setSituation(int situation) {
            this.situation = situation;
        }
    }

    /** Creates new form UserWindow */
    public JanelaCategoriaFinanceira(int newIdFinancialCategory) {
        try {
            // Define layout de acordo com o SO que estiver rodando
            UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
            this.setIconImage(JanelaLogin.icon);
            initComponents();
            idFinancialCategory = newIdFinancialCategory;
            configureWindow();
            this.setLocationRelativeTo(null);
            this.setVisible(true);
        } catch (Exception e) {
            MensagemExcessao.mostrarMensagem(e, this.getTitle());
        }
    }

    private LinkedList<String> getColumnNameSecondaryCategory() {
        LinkedList<String> columnNames = new LinkedList<String>();
        columnNames.add("");
        columnNames.add("Subcategoria");
        columnNames.add("Situação");
        return columnNames;
    }

    private void setEditSecondaryCategory(int idSecondaryCategory) {
        this.idSecondaryCategory = idSecondaryCategory;
        jButton2.setToolTipText("Editar");
        jButton2.setIcon(new Icons().getEdit());
        SecondaryCategoryObject secondaryCategoryObject = secondaryCategoryList.get(idPosition);
        jTextField2.setText(secondaryCategoryObject.getName());
        jComboBox1.setSelectedItem(SecondaryCategoryDao.getSituation(secondaryCategoryObject.getSituation()));
        jButton3.setEnabled(true);
        jTextField1.requestFocus();
    }

    private void cancelEditSecondaryCategory() {
        idSecondaryCategory = 0;
        idPosition = 0;
        jButton2.setToolTipText("Adicionar");
        jButton2.setIcon(new Icons().getAdd());
        jButton3.setEnabled(false);
        jTextField2.setText("");
        checkRequiredFields();
        jComboBox1.setSelectedIndex(0);
        jTextField2.requestFocus();
    }

    private void configureTable() {
        tableRender = new TableRender();
        tableModel = new TableModel(getColumnNameSecondaryCategory(), tableRender, new InterfaceTable() {

            public void tableAction(int id, int columnindex, int rowIndex) {
                if (columnindex < 0) {
                    idPosition = rowIndex;
                    setEditSecondaryCategory(id);
                }
            }

            public boolean isEditableColumn(int columnIndex) {
                if (columnIndex == 0) {
                    return true;
                }
                return false;
            }
        });
        jTable1.setModel(tableModel);
        jTable1.getColumnModel().getColumn(0).setMaxWidth(30);
        jTable1.getColumnModel().getColumn(0).setMinWidth(30);
        jTable1.getColumnModel().getColumn(0).setResizable(false);
        jTable1.getColumnModel().getColumn(1).setResizable(false);
        jTable1.getColumnModel().getColumn(2).setMaxWidth(80);
        jTable1.getColumnModel().getColumn(2).setMinWidth(80);
        jTable1.getColumnModel().getColumn(2).setResizable(false);
        TableRowComparator tableRowComparator = new TableRowComparator();
        tableRowSorter = tableRowComparator;
        jTable1.setRowSelectionAllowed(false);
    }

    private void checkRequiredFields() {
        ((TextFieldValidator) jTextField1).validarCampo();
        ((TextFieldValidator) jTextField2).validarCampo();
    }

    private void searchTable(boolean searchFromDatabase) {
        LinkedList searchResult = new LinkedList();

        LinkedList<Integer> columnId = new LinkedList<Integer>();
        LinkedList<String> columnName = new LinkedList<String>();
        LinkedList<String> columnSituation = new LinkedList<String>();

        if (searchFromDatabase) {
            searchResult = SecondaryCategoryDao.searchTable(idFinancialCategory);
            if (searchResult.size() > 0) {
                columnId = (LinkedList<Integer>) searchResult.get(0);
                columnName = (LinkedList<String>) searchResult.get(2);
                columnSituation = (LinkedList<String>) searchResult.get(3);
                for (int i = 0; i < columnId.size(); i++) {
                    SecondaryCategoryObject secondaryCategoryObject = new SecondaryCategoryObject();
                    secondaryCategoryObject.setIdFinancialCategory(idFinancialCategory);
                    secondaryCategoryObject.setIdSecondaryCategory(columnId.get(i));
                    secondaryCategoryObject.setName(columnName.get(i));
                    secondaryCategoryObject.setSituation(SecondaryCategoryDao.getSituation(columnSituation.get(i)));
                    secondaryCategoryList.add(secondaryCategoryObject);
                }
            }
        } else {
            for (int i = 0; i < secondaryCategoryList.size(); i++) {
                SecondaryCategoryObject secondaryCategoryObject = secondaryCategoryList.get(i);
                columnId.add(secondaryCategoryObject.getIdSecondaryCategory());
                columnName.add(secondaryCategoryObject.getName());
                columnSituation.add(SecondaryCategoryDao.getSituation(secondaryCategoryObject.getSituation()));
            }
            if (secondaryCategoryList.size() > 0) {
                searchResult.add(columnId);
                searchResult.add(Format.getBooleanLinkedList(columnId.size()));
                searchResult.add(columnName);
                searchResult.add(columnSituation);
            }

        }
        tableModel.update(searchResult);
        jTable1.setDefaultRenderer(Object.class, tableRender);
        tableRowSorter.setModel(tableModel);

        jTable1.setRowSorter(tableRowSorter);
    }

    private LinkedList<String> validateSecondaryCategoryFields() {
        LinkedList<String> fieldList = new LinkedList<String>();
        if (!((TextFieldValidator) jTextField2).validarCampo()) {
            fieldList.add(((TextFieldValidator) jTextField2).getjLabel().getText());
        }
        return fieldList;
    }

    private LinkedList<String> validateCategoryFields() {
        LinkedList<String> fieldList = new LinkedList<String>();
        if (!((TextFieldValidator) jTextField1).validarCampo()) {
            fieldList.add(((TextFieldValidator) jTextField1).getjLabel().getText());
        }
        return fieldList;
    }

    private void addCategory() {
        try {
            if (FinancialCategoryDao.getIdCategoryByName(jTextField1.getText()) == 0) {
                if (secondaryCategoryList.size() > 0) {
                    try {
                        JanelaLogin.connection.setAutoCommit(false);

                        boolean validate = true;
                        String message = "";

                        FinancialCategoryDao financialCategoryDao = new FinancialCategoryDao();
                        financialCategoryDao.setName(jTextField1.getText());
                        financialCategoryDao.setIdEntryType(EntryTypeDao.getIdEntryTypeByName(jComboBox2.getSelectedItem().toString()));
                        financialCategoryDao.inserir();

                        int idCategory = financialCategoryDao.getId();

                        for (int i = 0; i < secondaryCategoryList.size(); i++) {
                            SecondaryCategoryObject secondaryCategoryObject = secondaryCategoryList.get(i);
                            SecondaryCategoryDao secondaryCategoryDao = new SecondaryCategoryDao();
                            secondaryCategoryDao.setName(secondaryCategoryObject.getName());
                            secondaryCategoryDao.setSituation(secondaryCategoryObject.getSituation());
                            secondaryCategoryDao.setIdFinancialCategory(idCategory);
                            if (SecondaryCategoryDao.getIdSecondaryCategoryByName(secondaryCategoryDao.getName()) != 0) {
                                validate = false;
                                message = "A subcategoria (" + secondaryCategoryDao.getName() + ") pertence a outra categoria.";
                                i = secondaryCategoryList.size();
                            } else {
                                secondaryCategoryDao.inserir();
                            }
                        }
                        if (validate) {
                            JanelaLogin.connection.commit();
                            JOptionPane.showMessageDialog(null, "Categoria cadastrada com sucesso.", this.getTitle(), JOptionPane.INFORMATION_MESSAGE);
                            this.dispose();
                        } else {
                            JanelaLogin.connection.rollback();
                            JOptionPane.showMessageDialog(null, message, this.getTitle(), JOptionPane.INFORMATION_MESSAGE);
                        }
                    } catch (Exception e) {
                        JanelaLogin.connection.rollback();
                        MensagemExcessao.mostrarMensagem(e, this.getTitle());
                    } finally {
                        JanelaLogin.connection.setAutoCommit(true);
                    }
                } else {
                    JOptionPane.showMessageDialog(null, "É necessário que a categoria tenha no mínimo uma subcategoria.", this.getTitle(), JOptionPane.ERROR_MESSAGE);
                }
            } else {
                JOptionPane.showMessageDialog(null, "Esta categoria já esta cadastrado.", this.getTitle(), JOptionPane.ERROR_MESSAGE);
            }
        } catch (Exception ex) {
            MensagemExcessao.mostrarMensagem(ex, this.getTitle());
        }
    }

    private void editCategory() {
        try {
            FinancialCategoryDao financialCategoryDao = new FinancialCategoryDao();
            financialCategoryDao.buscar(idFinancialCategory);
            if (FinancialCategoryDao.getIdCategoryByName(jTextField1.getText()) == 0 || financialCategoryDao.getName().equals(jTextField1.getText())) {
                try {
                    JanelaLogin.connection.setAutoCommit(false);


                    financialCategoryDao.setName(jTextField1.getText());
                    financialCategoryDao.setIdEntryType(EntryTypeDao.getIdEntryTypeByName(jComboBox2.getSelectedItem().toString()));
                    financialCategoryDao.atualizar();

                    boolean validate = true;
                    String message = "";

                    for (int i = 0; i < secondaryCategoryList.size(); i++) {
                        SecondaryCategoryObject secondaryCategoryObject = secondaryCategoryList.get(i);
                        SecondaryCategoryDao secondaryCategoryDao = new SecondaryCategoryDao();
                        secondaryCategoryDao.setId(secondaryCategoryObject.getIdSecondaryCategory());
                        if (secondaryCategoryDao.getId() > 0) {//Esta subcategoria já esta cadastrada
                            secondaryCategoryDao.buscar(secondaryCategoryDao.getId());
                            secondaryCategoryDao.setName(secondaryCategoryObject.getName());
                            secondaryCategoryDao.setSituation(secondaryCategoryObject.getSituation());
                            secondaryCategoryDao.setIdFinancialCategory(idFinancialCategory);
                            int idSearchSecondary = SecondaryCategoryDao.getIdSecondaryCategoryByName(secondaryCategoryDao.getName());
                            if (idSearchSecondary == 0 || idSearchSecondary == secondaryCategoryDao.getId()) {
                                secondaryCategoryDao.atualizar();
                            } else {
                                validate = false;
                                message = "A subcategoria (" + secondaryCategoryDao.getName() + ") pertence a outra categoria.";
                                i = secondaryCategoryList.size();
                            }
                        } else {//Nova subcategoria
                            secondaryCategoryDao.setName(secondaryCategoryObject.getName());
                            secondaryCategoryDao.setSituation(secondaryCategoryObject.getSituation());
                            secondaryCategoryDao.setIdFinancialCategory(idFinancialCategory);
                            int idSearchSecondary = SecondaryCategoryDao.getIdSecondaryCategoryByName(secondaryCategoryDao.getName());
                            if (idSearchSecondary == 0) {
                                secondaryCategoryDao.inserir();
                            } else {
                                validate = false;
                                message = "A subcategoria (" + secondaryCategoryDao.getName() + ") pertence a outra categoria.";
                                i = secondaryCategoryList.size();
                            }
                        }
                    }
                    if (validate) {
                        JanelaLogin.connection.commit();
                        JOptionPane.showMessageDialog(null, "Categoria editada com sucesso.", this.getTitle(), JOptionPane.INFORMATION_MESSAGE);
                        this.dispose();
                    } else {
                        JanelaLogin.connection.rollback();
                        JOptionPane.showMessageDialog(null, message, this.getTitle(), JOptionPane.INFORMATION_MESSAGE);
                    }
                } catch (Exception e) {
                    JanelaLogin.connection.rollback();
                    MensagemExcessao.mostrarMensagem(e, this.getTitle());
                } finally {
                    JanelaLogin.connection.setAutoCommit(true);
                }
            } else {
                JOptionPane.showMessageDialog(null, "Este email já esta cadastrado.", this.getTitle(), JOptionPane.ERROR_MESSAGE);
            }
        } catch (Exception ex) {
            MensagemExcessao.mostrarMensagem(ex, this.getTitle());
        }
    }

    private void setSecondaryCategory(String type) {
        try {
            LinkedList tableData = tableModel.getData();
            LinkedList<String> secondaryCategoryColumnName = (tableData.size() > 0) ? (LinkedList<String>) tableData.get(1) : new LinkedList<String>();

            String name = jTextField2.getText();
            String situation = jComboBox1.getSelectedItem().toString();
            if ((SecondaryCategoryDao.getIdSecondaryCategoryByName(name) == 0 && !secondaryCategoryColumnName.contains(name))
                    || (type.equalsIgnoreCase("edit") && !((((LinkedList<String>) tableData.get(2)).get(idPosition)).equalsIgnoreCase(situation)))) {
                if (type.equalsIgnoreCase("add")) {
                    SecondaryCategoryObject secondaryCategoryObject = new SecondaryCategoryObject();
                    secondaryCategoryObject.setName(name);
                    secondaryCategoryObject.setIdSecondaryCategory(secondaryCategoryList.size() + 1 * -1);
                    secondaryCategoryObject.setSituation(SecondaryCategoryDao.getSituation(situation));
                    secondaryCategoryList.add(secondaryCategoryObject);
                } else if (type.equalsIgnoreCase("edit")) {
                    SecondaryCategoryObject secondaryCategoryObject = secondaryCategoryList.get(idPosition);
                    secondaryCategoryObject.setName(name);
                    secondaryCategoryObject.setSituation(SecondaryCategoryDao.getSituation(situation));
                    secondaryCategoryList.set(idPosition, secondaryCategoryObject);
                }
                cancelEditSecondaryCategory();
                searchTable(false);
            } else {
                JOptionPane.showMessageDialog(null, "Esta subcategoria já existe.", this.getTitle(), JOptionPane.ERROR_MESSAGE);
            }
        } catch (Exception ex) {
            MensagemExcessao.mostrarMensagem(ex, this.getTitle());
        }
    }

    private void setFinacialCategoryInformations() {
        jButton1.setText("Editar");
        jButton1.setIcon(new Icons().getEdit());

        FinancialCategoryDao financialCategoryDao = new FinancialCategoryDao();
        financialCategoryDao.buscar(idFinancialCategory);
        jTextField1.setText(financialCategoryDao.getName());
        jComboBox2.setSelectedItem(EntryTypeDao.getNameByIdEntryType(financialCategoryDao.getIdEntryType()));
    }

    /**
     * Inicializando as configurações da tela
     * @throws SQLException 
     */
    private void configureWindow() throws SQLException {
        configureTable();

        secondaryCategoryList = new LinkedList<SecondaryCategoryObject>();

        LinkedList<String> entryTypes = EntryTypeDao.getListEntryTypes();
        for (int i = 0; i < entryTypes.size(); i++) {
            jComboBox2.addItem(entryTypes.get(i));
        }
        if (idFinancialCategory != 0) { // Edição de usuário
            setFinacialCategoryInformations();
            searchTable(true);
        } else {
            searchTable(false);
        }
        checkRequiredFields();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel3 = new javax.swing.JPanel();
        jPanel1 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        jTextField1 = new manager.helpers.validation.TextFieldValidator(80,-1,true,true,"text",jLabel1);
        jPanel2 = new javax.swing.JPanel();
        jLabel2 = new javax.swing.JLabel();
        jTextField2 = new TextFieldValidator(80, -1, true, true, "text", jLabel2);
        jButton2 = new javax.swing.JButton();
        jButton3 = new javax.swing.JButton();
        jScrollPane1 = new javax.swing.JScrollPane();
        jTable1 = new javax.swing.JTable();
        jComboBox1 = new javax.swing.JComboBox();
        jLabel3 = new javax.swing.JLabel();
        jButton1 = new javax.swing.JButton();
        jButton6 = new javax.swing.JButton();
        jComboBox2 = new javax.swing.JComboBox();
        jLabel4 = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("Categorias Financeiras");
        setBackground(Configurations.getBackGroundColor());
        setMinimumSize(new java.awt.Dimension(460, 457));
        addComponentListener(new java.awt.event.ComponentAdapter() {
            public void componentResized(java.awt.event.ComponentEvent evt) {
                formComponentResized(evt);
            }
        });

        jPanel3.setBackground(Configurations.getBackGroundColor());
        jPanel3.setPreferredSize(new java.awt.Dimension(700, 320));
        jPanel3.setLayout(null);

        jPanel1.setBackground(Configurations.getBackGroundColor());
        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder(""));
        jPanel1.setLayout(null);

        jLabel1.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        jLabel1.setText("Name");
        jPanel1.add(jLabel1);
        jLabel1.setBounds(20, 20, 220, 14);

        jTextField1.setNextFocusableComponent(jComboBox2);
        jPanel1.add(jTextField1);
        jTextField1.setBounds(20, 40, 255, 20);

        jPanel2.setBackground(Configurations.getBackGroundColor());
        jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder("SUBCATEGORIAS"));
        jPanel2.setLayout(null);

        jLabel2.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        jLabel2.setText("Subcategoria");
        jPanel2.add(jLabel2);
        jLabel2.setBounds(10, 20, 120, 14);

        jTextField2.setNextFocusableComponent(jButton2);
        jPanel2.add(jTextField2);
        jTextField2.setBounds(10, 40, 225, 20);

        jButton2.setIcon(new javax.swing.ImageIcon(getClass().getResource("/manager/images/add.png"))); // NOI18N
        jButton2.setToolTipText("Adicionar");
        jButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton2ActionPerformed(evt);
            }
        });
        jPanel2.add(jButton2);
        jButton2.setBounds(330, 25, 30, 30);

        jButton3.setIcon(new javax.swing.ImageIcon(getClass().getResource("/manager/images/cancel.png"))); // NOI18N
        jButton3.setToolTipText("Cancelar");
        jButton3.setEnabled(false);
        jButton3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton3ActionPerformed(evt);
            }
        });
        jPanel2.add(jButton3);
        jButton3.setBounds(370, 25, 30, 30);

        jScrollPane1.setViewportView(jTable1);

        jPanel2.add(jScrollPane1);
        jScrollPane1.setBounds(10, 70, 400, 250);

        jComboBox1.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "ATIVADO", "DESATIVADO" }));
        jComboBox1.setNextFocusableComponent(jButton2);
        jPanel2.add(jComboBox1);
        jComboBox1.setBounds(240, 40, 80, 20);

        jLabel3.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        jLabel3.setText("Situação");
        jPanel2.add(jLabel3);
        jLabel3.setBounds(240, 20, 80, 14);

        jPanel1.add(jPanel2);
        jPanel2.setBounds(20, 70, 420, 340);

        jButton1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/manager/images/add.png"))); // NOI18N
        jButton1.setText("Cadastrar");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });
        jPanel1.add(jButton1);
        jButton1.setBounds(20, 420, 100, 23);

        jButton6.setIcon(new javax.swing.ImageIcon(getClass().getResource("/manager/images/cancel.png"))); // NOI18N
        jButton6.setText("Cancelar");
        jButton6.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton6ActionPerformed(evt);
            }
        });
        jPanel1.add(jButton6);
        jButton6.setBounds(130, 420, 100, 23);

        jComboBox2.setNextFocusableComponent(jTextField2);
        jPanel1.add(jComboBox2);
        jComboBox2.setBounds(280, 40, 160, 20);

        jLabel4.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        jLabel4.setText("Tipo de Lançamento");
        jPanel1.add(jLabel4);
        jLabel4.setBounds(280, 20, 160, 14);

        jPanel3.add(jPanel1);
        jPanel1.setBounds(0, 0, 460, 457);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel3, javax.swing.GroupLayout.DEFAULT_SIZE, 460, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel3, javax.swing.GroupLayout.DEFAULT_SIZE, 457, Short.MAX_VALUE)
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void formComponentResized(java.awt.event.ComponentEvent evt) {//GEN-FIRST:event_formComponentResized
        WindowsFunctions.resizePanel(jPanel3, jPanel1);
    }//GEN-LAST:event_formComponentResized

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        LinkedList<String> fieldValidadeList = validateCategoryFields();
        if (fieldValidadeList.size() == 0) {
            if (idFinancialCategory == 0) {
                addCategory();
            } else {
                editCategory();
            }
        } else {
            JOptionPane.showMessageDialog(null, ValidationFunctions.getValidationMessage(fieldValidadeList), this.getTitle(), JOptionPane.ERROR_MESSAGE);
        }
    }//GEN-LAST:event_jButton1ActionPerformed

    private void jButton6ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton6ActionPerformed
        this.dispose();
    }//GEN-LAST:event_jButton6ActionPerformed

    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
        LinkedList<String> fieldValidadeList = validateSecondaryCategoryFields();
        if (fieldValidadeList.size() == 0) {
            if (idSecondaryCategory == 0) {
                setSecondaryCategory("add");
            } else {
                setSecondaryCategory("edit");
            }
        } else {
            JOptionPane.showMessageDialog(null, ValidationFunctions.getValidationMessage(fieldValidadeList), this.getTitle(), JOptionPane.ERROR_MESSAGE);
        }
}//GEN-LAST:event_jButton2ActionPerformed

    private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton3ActionPerformed
        cancelEditSecondaryCategory();
}//GEN-LAST:event_jButton3ActionPerformed
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton2;
    private javax.swing.JButton jButton3;
    private javax.swing.JButton jButton6;
    private javax.swing.JComboBox jComboBox1;
    private javax.swing.JComboBox jComboBox2;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTable jTable1;
    private javax.swing.JTextField jTextField1;
    private javax.swing.JTextField jTextField2;
    // End of variables declaration//GEN-END:variables
}
